package com.wfs.array;

import java.util.Arrays;

/**
 * 开发一个简易版的斗地主游戏，要求只完成做牌（存储54张牌）、洗牌。
 * 牌编号：2-10,J,Q,K,A,小王,大王
 * 牌花色：♦,♣,♥,♠
 */
public class ArrayDemo3 {
    public static void main(String[] args) {
         String[] pokers = createPoker();
         shufflePoker(pokers);
    }
    /**
     * 创建一个数组，存储54张牌
     */
    static String[] createPoker() {
        String[] colors = {"♦", "♣", "♥", "♠"};
        String[] numbers = {"A", "2","3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
        int index = 0;
        String[] pokers = new String[54];
        for (int i = 0; i < numbers.length; i++) {
            for (int i1 = 0; i1 < colors.length; i1++) {
                pokers[index++] = colors[i1] + numbers[i];
            }
        }
        pokers[52] = "小王";
        pokers[53] = "大王";
        System.out.println(Arrays.toString(pokers));
        return pokers;
    }
    /**
     * 洗牌
     */
    static void shufflePoker(String[] pokers) {
        for (int i = 0; i < pokers.length; i++) {
            // Math.random() [0.0-1.0)
            int index0 = (int) (Math.random() * 54);// [0.54)=====>[0-53]
            int index1 = (int) (Math.random() * 54);
            // 数组的交换
            String temp;
            temp = pokers[index0];
            pokers[index0] = pokers[index1];
            pokers[index1] = temp;
        }
        System.out.println(Arrays.toString(pokers));
    }
}
